# -*- coding: utf-8 -*-

from flask import Flask
from flask import jsonify
from flask import render_template

app = Flask(__name__)

@app.route('/')
@app.route('/<page>')
def main_page(page=None):
    tpl = 'index.html'
    if page != None:
        tpl = page
    return render_template(tpl)


@app.route('/api/system/base')
def getSystemBaseInfo():
    import psutil
    import time
    infoDict = {}
    infoDict['cpu_percent'] = psutil.cpu_percent(1)
    virMem = psutil.virtual_memory()
    infoDict['mem_percent'] = virMem.percent
    infoDict['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
    infoDict['timestamp'] = int(time.time() * 1000)
    return jsonify(infoDict)


if __name__ == '__main__':
    app.run(debug=True)
    
